/* Copyright (c) 2010, Peter Lényi */
/* Licensed under The BSD License. */

package gem.apps.fs.db;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;

/**
 * Interface FileManager defines API for the file storage.
 * 
 * @author Peter Lényi
 * @version 20100425F
 */
public interface FileManager
{
    /**
     * Store file in local filesystem.
     * @param file
     *          target file in local filesystem; name of this file should be unique
     *          identification number assigned by the system.
     * @param os
     *          data stream from original file.
     * @throws FileStorageException
     *          if an exception occured in the process.
     */
    void storeFile(File file, InputStream os) throws FileStorageException;

    /**
     * Check if file with such name exists.
     * @param uin
     *          file's unique identification number assigned by the system.
     * @return true iff file exists; or false otherwise.
     * @throws FileStorageException
     *          if an exception occured in the process.
     */
    boolean exists(long uin) throws FileStorageException;

    /**
     * Check if file with such name is a file, not a directory.
     * @param uin
     *          file's unique identification number assigned by the system.
     * @return true iff file is a file; or false otherwise.
     * @throws FileStorageException
     *          if an exception occured in the process.
     */
    boolean isFile(long uin) throws FileStorageException;

    /**
     * Retrieve a specific file to be sent to browser.
     * @param uin
     *          file's unique identification number assigned by the system.
     * @return stream to file in local filesystem.
     * @throws FileStorageException
     *          if an exception occured in the process.
     */
    FileInputStream loadFile(long uin) throws FileStorageException;

    /**
     * Delete file in local filesystem.
     * @param uin
     *          file's unique identification number assigned by the system.
     * @throws FileStorageException
     *          if an exception occured in the process.
     */
    void deleteFile(long uin) throws FileStorageException;
}
